Skip to content

Conversation

@aadeshps-mcw
Copy link
Contributor

--Test that verifies correct emission of OpEntryPoint and interface variables for SPIR-V when using multiple global constants in the kernel entry point.
--Test that verifies code generation for get_global_size() calls.
--Test that verifies SPIR-V layout and initialization of various global variables.

@llvmbot
Copy link
Member

llvmbot commented Aug 1, 2025

@llvm/pr-subscribers-backend-spir-v

Author: Aadesh Premkumar (aadeshps-mcw)

Changes

--Test that verifies correct emission of OpEntryPoint and interface variables for SPIR-V when using multiple global constants in the kernel entry point.
--Test that verifies code generation for get_global_size() calls.
--Test that verifies SPIR-V layout and initialization of various global variables.


Full diff: https://github.com/llvm/llvm-project/pull/151648.diff

3 Files Affected:

  • (added) llvm/test/CodeGen/SPIRV/entry-point-interfaces.ll (+31)
  • (added) llvm/test/CodeGen/SPIRV/get_global_size.ll (+50)
  • (added) llvm/test/CodeGen/SPIRV/layout.ll (+87)
diff --git a/llvm/test/CodeGen/SPIRV/entry-point-interfaces.ll b/llvm/test/CodeGen/SPIRV/entry-point-interfaces.ll
new file mode 100644
index 0000000000000..f1e092732558e
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/entry-point-interfaces.ll
@@ -0,0 +1,31 @@
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; CHECK: OpEntryPoint Kernel %[[#Func:]] "test" %[[#Interface1:]] %[[#Interface2:]] %[[#Interface3:]] %[[#Interface4:]]
+; CHECK-DAG: OpName %[[#Func]] "test"
+; CHECK-DAG: OpName %[[#Interface1]] "var"
+; CHECK-DAG: OpName %[[#Interface3]] "var2"
+; CHECK-DAG: OpName %[[#Interface2]] "var.const"
+; CHECK-DAG: OpName %[[#Interface4]] "var2.const"
+; CHECK-DAG: %[[#TypeInt:]] = OpTypeInt  32 0
+; CHECK-DAG: %[[#Const1:]] = OpConstant %[[#TypeInt]] 1
+; CHECK-DAG: %[[#Const2:]] = OpConstant %[[#TypeInt]] 3
+
+; CHECK: %[[#Interface1]] = OpVariable %[[#]] UniformConstant %[[#Const1]]
+; CHECK: %[[#Interface3]] = OpVariable %[[#]] UniformConstant %[[#Const2]]
+; CHECK: %[[#Interface2]] = OpVariable %[[#]] UniformConstant %[[#Const1]]
+; CHECK: %[[#Interface4]] = OpVariable %[[#]] UniformConstant %[[#Const2]]
+
+@var = dso_local addrspace(2) constant i32 1, align 4
+@var2 = dso_local addrspace(2) constant i32 3, align 4
+@var.const = private unnamed_addr addrspace(2) constant i32 1, align 4
+@var2.const = private unnamed_addr addrspace(2) constant i32 3, align 4
+
+define dso_local spir_kernel void @test() {
+entry:
+  %0 = load i32, ptr addrspace(2) @var.const, align 4
+  %1 = load i32, ptr addrspace(2) @var2.const, align 4
+  %mul = mul nsw i32 %0, %1
+  %mul1 = mul nsw i32 %mul, 2
+  ret void
+}
diff --git a/llvm/test/CodeGen/SPIRV/get_global_size.ll b/llvm/test/CodeGen/SPIRV/get_global_size.ll
new file mode 100644
index 0000000000000..959371a7d21e7
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/get_global_size.ll
@@ -0,0 +1,50 @@
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; CHECK: %[[#int32:]] = OpTypeInt 32 0
+; CHECK: %[[#int64:]] = OpTypeInt 64 0
+; CHECK: %[[#vec3:]] = OpTypeVector %[[#int64]] 3
+; CHECK: %[[#ptr_input_vec3:]] = OpTypePointer Input %[[#vec3]]
+; CHECK: %[[#global_size_var:]] = OpVariable %[[#ptr_input_vec3]] Input
+
+; CHECK: %[[#load_gs1:]] = OpLoad %[[#vec3]] %[[#global_size_var]] Aligned 1
+; CHECK: %[[#extract3:]] = OpCompositeExtract %[[#int64]] %[[#load_gs1]] 0
+
+; CHECK: %[[#bitcast1:]] = OpBitcast %[[#]] %[[#]]
+; CHECK: %[[#load_out1:]] = OpLoad %[[#]] %[[#bitcast1]] Aligned 8
+; CHECK: %[[#gep1:]] = OpInBoundsPtrAccessChain %[[#]] %[[#load_out1]] %[[#]]
+; CHECK: OpStore %[[#gep1]] %[[#extract3]] Aligned 8
+
+; CHECK: %[[#load_param_x:]] = OpLoad %[[#int32]] %[[#]]
+; CHECK: %[[#load_gs2:]] = OpLoad %[[#vec3]] %[[#global_size_var]] Aligned 1
+; CHECK: %[[#dyn_extract:]] = OpVectorExtractDynamic %[[#int64]] %[[#load_gs2]] %[[#load_param_x]]
+; CHECK: %[[#cmp:]] = OpULessThan %[[#]] %[[#load_param_x]] %[[#]]
+; CHECK: %[[#select2:]] = OpSelect %[[#int64]] %[[#cmp]] %[[#dyn_extract]] %[[#]]
+; CHECK: %[[#bitcast2:]] = OpBitcast %[[#]] %[[#]]
+; CHECK: %[[#load_out2:]] = OpLoad %[[#]] %[[#bitcast2]] Aligned 8
+; CHECK: %[[#gep2:]] = OpInBoundsPtrAccessChain %[[#]] %[[#load_out2]] %[[#]]
+; CHECK: OpStore %[[#gep2]] %[[#select2]] Aligned 8
+
+define dso_local spir_kernel void @ggs(ptr noundef align 8 %out, i32 noundef %x) {
+entry:
+  %out.addr = alloca ptr, align 8
+  %x.addr = alloca i32, align 4
+  store ptr %out, ptr %out.addr, align 8
+  store i32 %x, ptr %x.addr, align 4
+  %call = call i64 @_Z15get_global_sizej(i32 noundef 0)
+  %0 = load ptr, ptr %out.addr, align 8
+  %arrayidx = getelementptr inbounds i64, ptr %0, i64 0
+  store i64 %call, ptr %arrayidx, align 8
+  %call1 = call i64 @_Z15get_global_sizej(i32 noundef 3)
+  %1 = load ptr, ptr %out.addr, align 8
+  %arrayidx2 = getelementptr inbounds i64, ptr %1, i64 1
+  store i64 %call1, ptr %arrayidx2, align 8
+  %2 = load i32, ptr %x.addr, align 4
+  %call3 = call i64 @_Z15get_global_sizej(i32 noundef %2)
+  %3 = load ptr, ptr %out.addr, align 8
+  %arrayidx4 = getelementptr inbounds i64, ptr %3, i64 2
+  store i64 %call3, ptr %arrayidx4, align 8
+  ret void
+}
+
+declare i64 @_Z15get_global_sizej(i32 noundef)
diff --git a/llvm/test/CodeGen/SPIRV/layout.ll b/llvm/test/CodeGen/SPIRV/layout.ll
new file mode 100644
index 0000000000000..016bf7479fb98
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/layout.ll
@@ -0,0 +1,87 @@
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; CHECK: OpCapability Kernel
+; CHECK: OpCapability Addresses
+; CHECK: OpCapability GenericPointer
+; CHECK: OpCapability Int64
+; CHECK: OpCapability Int8
+; CHECK: OpCapability Linkage
+
+; CHECK: OpExtInstImport "OpenCL.std"
+; CHECK: OpMemoryModel Physical64 OpenCL
+; CHECK: OpEntryPoint Kernel %[[#]] "foo" %[[#]]
+; CHECK: OpSource OpenCL_C 200000
+
+; CHECK-DAG: OpName %[[#]]
+
+; CHECK-DAG: OpDecorate %[[#]]
+
+; CHECK: %[[TYPE_I8:[0-9]+]] = OpTypeInt 8 0
+; CHECK: %[[PTR_CW_I8:[0-9]+]] = OpTypePointer CrossWorkgroup %[[TYPE_I8]]
+; CHECK: %[[TYPE_VOID:[0-9]+]] = OpTypeVoid
+; CHECK: %[[FTYPE_BAR1:[0-9]+]] = OpTypeFunction %[[TYPE_VOID]] %[[PTR_CW_I8]]
+; CHECK: %[[TYPE_I32:[0-9]+]] = OpTypeInt 32 0
+; CHECK: %[[VEC3_I32:[0-9]+]] = OpTypeVector %[[TYPE_I32]] 3
+; CHECK: %[[FTYPE_BAR2:[0-9]+]] = OpTypeFunction %[[TYPE_VOID]] %[[PTR_CW_I8]] %[[VEC3_I32]]
+; CHECK: %[[VEC4_I32:[0-9]+]] = OpTypeVector %[[TYPE_I32]] 4
+; CHECK: %[[PTR_UC_VEC4:[0-9]+]] = OpTypePointer UniformConstant %[[VEC4_I32]]
+; CHECK: %[[PTR_GEN_I8:[0-9]+]] = OpTypePointer Generic %[[TYPE_I8]]
+; CHECK: %[[STRUCT_B:[0-9]+]] = OpTypeStruct %[[TYPE_I32]] %[[PTR_GEN_I8]]
+; CHECK: %[[STRUCT_C:[0-9]+]] = OpTypeStruct %[[TYPE_I32]] %[[STRUCT_B]]
+; CHECK: %[[STRUCT_A:[0-9]+]] = OpTypeStruct %[[TYPE_I32]] %[[STRUCT_C]]
+; CHECK: %[[TYPE_F32:[0-9]+]] = OpTypeFloat 32
+; CHECK: %[[CONST_2:[0-9]+]] = OpConstant %[[TYPE_I32]] 2
+; CHECK: %[[ARRAY_F:[0-9]+]] = OpTypeArray %[[TYPE_F32]] %[[CONST_2]]
+; CHECK: %[[ARRAY_I:[0-9]+]] = OpTypeArray %[[TYPE_I32]] %[[CONST_2]]
+; CHECK: %[[PTR_UC_VEC3:[0-9]+]] = OpTypePointer UniformConstant %[[VEC3_I32]]
+; CHECK: %[[PTR_CW_STRUCTA:[0-9]+]] = OpTypePointer CrossWorkgroup %[[STRUCT_A]]
+; CHECK: %[[PTR_UC_ARRAYF:[0-9]+]] = OpTypePointer UniformConstant %[[ARRAY_F]]
+; CHECK: %[[PTR_CW_PTR_CW_I8:[0-9]+]] = OpTypePointer CrossWorkgroup %[[PTR_CW_I8]]
+; CHECK: %[[TYPE_I64:[0-9]+]] = OpTypeInt 64 0
+; CHECK: %[[PTR_CW_ARRAYI:[0-9]+]] = OpTypePointer CrossWorkgroup %[[ARRAY_I]]
+
+; CHECK: %[[C_NULL_I32:[0-9]+]] = OpConstantNull %[[TYPE_I32]]
+; CHECK: %[[C_I64_4:[0-9]+]] = OpConstant %[[TYPE_I64]] 4
+; CHECK: %[[C_I32_1:[0-9]+]] = OpConstant %[[TYPE_I32]] 1
+; CHECK: %[[C_COMP_I32:[0-9]+]] = OpConstantComposite %[[ARRAY_I]] %[[C_I32_1]] %[[CONST_2]]
+
+; CHECK: %[[VAR_V:[0-9]+]] = OpVariable %[[PTR_CW_ARRAYI]] CrossWorkgroup %[[C_COMP_I32]]
+; CHECK: %[[SPECCONSTOP:[0-9]+]] = OpSpecConstantOp %[[PTR_CW_I8]] InBoundsPtrAccessChain %[[VAR_V]] %[[C_NULL_I32]] %[[C_I64_4]]
+; CHECK: %[[VAR_S:[0-9]+]] = OpVariable %[[PTR_CW_PTR_CW_I8]] CrossWorkgroup %[[SPECCONSTOP]]
+; CHECK: %[[NULL_F:[0-9]+]] = OpConstantNull %[[ARRAY_F]]
+; CHECK: %[[VAR_F:[0-9]+]] = OpVariable %[[PTR_UC_ARRAYF]] UniformConstant %[[NULL_F]]
+; CHECK: %[[NULL_STRUCT_A:[0-9]+]] = OpConstantNull %[[STRUCT_A]]
+; CHECK: %[[VAR_A:[0-9]+]] = OpVariable %[[PTR_CW_STRUCTA]] CrossWorkgroup %[[NULL_STRUCT_A]]
+; CHECK: %[[VAR_B:[0-9]+]] = OpVariable %[[PTR_UC_VEC3]] UniformConstant
+
+; CHECK: %[[BAR1:[0-9]+]] = OpFunction %[[TYPE_VOID]] None %[[FTYPE_BAR1]]
+; CHECK: %[[P_A1:[0-9]+]] = OpFunctionParameter %[[PTR_CW_I8]]
+; CHECK: OpFunctionEnd
+
+@v = addrspace(1) global [2 x i32] [i32 1, i32 2], align 4
+@s = addrspace(1) global ptr addrspace(1) getelementptr inbounds ([2 x i32], ptr addrspace(1) @v, i32 0, i32 1), align 4
+
+%struct.A = type { i32, %struct.C }
+%struct.C = type { i32, %struct.B }
+%struct.B = type { i32, ptr addrspace(4) }
+
+@f = addrspace(2) constant [2 x float] zeroinitializer, align 4
+@b = external addrspace(2) constant <3 x i32>
+@a = common addrspace(1) global %struct.A zeroinitializer, align 4
+
+define spir_kernel void @foo(ptr addrspace(1) %a) {
+entry:
+  call spir_func void @bar1(ptr addrspace(1) %a)
+  %loadVec4 = load <4 x i32> , ptr addrspace(2) @b
+  %extractVec = shufflevector <4 x i32> %loadVec4, <4 x i32> undef, <3 x i32> <i32 0, i32 1, i32 2>
+  call spir_func void @bar2(ptr addrspace(1) %a, <3 x i32> %extractVec)
+  ret void
+}
+
+declare spir_func void @bar1(ptr addrspace(1))
+declare spir_func void @bar2(ptr addrspace(1), <3 x i32>)
+
+!opencl.ocl.version = !{!7}
+
+!7 = !{i32 2, i32 0}

@github-actions
Copy link

github-actions bot commented Aug 1, 2025

✅ With the latest revision this PR passed the undef deprecator.

@aadeshps-mcw aadeshps-mcw marked this pull request as draft August 1, 2025 06:34
…ariables for SPIR-V when using multiple global constants in the kernel entry point.

--Test that verifies code generation for get_global_size() calls.
--Test that verifies SPIR-V layout and initialization of various global variables.
@aadeshps-mcw aadeshps-mcw marked this pull request as ready for review August 1, 2025 08:44
@michalpaszkowski
Copy link
Member

Thanks for the PR! LGTM!

@michalpaszkowski michalpaszkowski merged commit 95e96b9 into llvm:main Aug 3, 2025
12 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 3, 2025

LLVM Buildbot has detected a new failure on builder lldb-x86_64-debian running on lldb-x86_64-debian while building llvm at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/162/builds/28177

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: functionalities/inferior-changed/TestInferiorChanged.py (243 of 3128)
PASS: lldb-api :: functionalities/thread/num_threads/TestNumThreads.py (244 of 3128)
PASS: lldb-api :: python_api/process/cancel_attach/TestCancelAttach.py (245 of 3128)
PASS: lldb-api :: functionalities/data-formatter/data-formatter-stl/generic/shared_ptr/TestDataFormatterStdSharedPtr.py (246 of 3128)
PASS: lldb-api :: functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py (247 of 3128)
PASS: lldb-api :: functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py (248 of 3128)
PASS: lldb-api :: functionalities/exec/TestExec.py (249 of 3128)
PASS: lldb-api :: functionalities/tail_call_frames/thread_step_out_message/TestArtificialFrameStepOutMessage.py (250 of 3128)
PASS: lldb-api :: tools/lldb-dap/locations/TestDAP_locations.py (251 of 3128)
PASS: lldb-api :: functionalities/jitloader_gdb/TestJITLoaderGDB.py (252 of 3128)
FAIL: lldb-api :: tools/lldb-dap/output/TestDAP_output.py (253 of 3128)
******************** TEST 'lldb-api :: tools/lldb-dap/output/TestDAP_output.py' FAILED ********************
Script:
--
/usr/bin/python3 /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/./lib --env LLVM_INCLUDE_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/include --env LLVM_TOOLS_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/./bin --arch x86_64 --build-dir /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex --lldb-module-cache-dir /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/worker/2.0.1/lldb-x86_64-debian/build/./bin/lldb --compiler /home/worker/2.0.1/lldb-x86_64-debian/build/./bin/clang --dsymutil /home/worker/2.0.1/lldb-x86_64-debian/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/worker/2.0.1/lldb-x86_64-debian/build/./bin --lldb-obj-root /home/worker/2.0.1/lldb-x86_64-debian/build/tools/lldb --lldb-libs-dir /home/worker/2.0.1/lldb-x86_64-debian/build/./lib --cmake-build-type Release -t /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/tools/lldb-dap/output -p TestDAP_output.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 22.0.0git (https://github.com/llvm/llvm-project.git revision 95e96b94d75e975470ccb7dfa41df776bb289f8d)
  clang revision 95e96b94d75e975470ccb7dfa41df776bb289f8d
  llvm revision 95e96b94d75e975470ccb7dfa41df776bb289f8d
Skipping the following test categories: ['libc++', 'msvcstl', 'dsym', 'gmodules', 'debugserver', 'objc']

--
Command Output (stderr):
--
Change dir to: /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/tools/lldb-dap/output
runCmd: settings clear --all

output: 

runCmd: settings set symbols.enable-external-lookup false

output: 

runCmd: settings set target.inherit-tcc true

output: 

runCmd: settings set target.disable-aslr false

output: 

runCmd: settings set target.detach-on-error false

output: 


@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 3, 2025

LLVM Buildbot has detected a new failure on builder openmp-s390x-linux running on systemz-1 while building llvm at step 6 "test-openmp".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/88/builds/14677

Here is the relevant piece of the build log for the reference
Step 6 (test-openmp) failure: test (failure)
******************** TEST 'libomp :: tasking/issue-94260-2.c' FAILED ********************
Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang -fopenmp   -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test -L /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src  -fno-omit-frame-pointer -mbackchain -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c -o /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp -lm -latomic && /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang -fopenmp -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test -L /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -fno-omit-frame-pointer -mbackchain -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c -o /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp -lm -latomic
# executed command: /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--

********************


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants